package com.mvc.gulimall.search.controller;

import com.mvc.common.es.SkuEsMode;
import com.mvc.common.exception.BizCodeEnum;
import com.mvc.common.utils.R;
import com.mvc.gulimall.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
@Slf4j
@RequestMapping("/search/save")
@RestController
public class ElasticSaveController {
    @Autowired
    private ProductSaveService productSaveService;
    //上架商品
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsMode> skuEsModes) {
        Boolean b=true;
        try {
         b = productSaveService.productStatusUp(skuEsModes);
        } catch (IOException e) {
//            log.error("ElasticSaveController商城上架错误{}",e);
          return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMessage());
        }
        if (b){
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMessage());
        }else {
          return R.ok();
        }

    }
 }
